//index.js
//获取应用实例
const app = getApp()

Page({
  data:{
    swiper:[
      {
        src:"../../assets/banner/banner1.webp"
      },
      {
        src:"../../assets/banner/banner2.webp"
      },
      {
        src:"../../assets/banner/banner3.webp"
      },
      {
        src:"../../assets/banner/banner4.webp"
      },
      {
        src:"../../assets/banner/banner5.webp"
      },
      {
        src:"../../assets/banner/banner6.webp"
      }
    ],
    topNav:[],
    bottomCon:[],
  },
  showok:function(e){
    wx.showToast({
      title: '成功加入购物车',
    })
    let id=e.currentTarget.dataset.id
    let val=this.data.bottomCon[id]
    let lists=wx.getStorageSync('goods')
    let goods=[]
    if(lists){
      lists.forEach(item=>{
        goods.push(item)
      })
      goods.push(val)
      wx.setStorageSync('goods', goods)
    }else{
      wx.setStorageSync('goods', [val])
    }
  },
  onLoad(){
    wx.request({
      url: 'https://www.fastmock.site/mock/ae21632f928365f79e5f158f5ad09f6b/hema/goodsSorts',
      success: (res) => {
        this.setData({
          topNav: res.data.data
        })
      }
    })
    wx.request({
      url: 'https://www.fastmock.site/mock/ae21632f928365f79e5f158f5ad09f6b/hema/home2',
      success: (res) => {
        this.setData({
          bottomCon: res.data.data
        })
      }
    })
  },
})
